#ifndef WIDGET_H
#define WIDGET_H

#include "t_av_packet.h"
#include "my_SDL_compat.h"

#include <QtCore>
#include <QtGui>
#include <QtMultimedia>
#include <QtNetwork>

#include "misc.h"
#include "t_generator.h"

class T_ScreenWidget : public QWidget
{
public:
    QSize m_size;
    SDL_Surface *screen;

    explicit T_ScreenWidget(QWidget *parent = 0)
        : QWidget(parent)
        , m_size(QSize(200, 100))
    {
        //QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
        sizePolicy.setHorizontalStretch(1);
        sizePolicy.setVerticalStretch(1);
        sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
        this->setSizePolicy(sizePolicy);
    }
    virtual void setScreenSize(QSize a_size)
    {
        m_size = a_size;
    }
    virtual QSize sizeHint () const
    {
        return m_size;

    }
};

class T_Packet_Thread : public QThread
{
protected:
    T_Box_Player_Context *m_player_ctx;
public:
    explicit T_Packet_Thread(T_Box_Player_Context *a_player_ctx)
        : m_player_ctx(a_player_ctx)
    {
    }
    virtual void run();
};

namespace Ui {
    class Widget;
}
class T_Box_Input;
class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    Ui::Widget *ui;
public:
    T_ScreenWidget *screenWidget;

    //T_Box_Input_File *m_media_input;
    T_Box_Input *m_media_input;
    T_Box_Player_Context *m_player_ctx;
    T_Packet_Thread *m_packet_thread;
    QString		filename;
    QTimer m_video_timer;
    int m_drop_count;
    T_FPS m_fps1;
    T_FPS m_fps2;
    T_FPS m_fps_download;


    QMutex m_frame_mutex;

    SDL_Window *window_id;

    T_Generator *m_generator;
    QAudioDeviceInfo m_device;
    QAudioFormat m_format;
    QAudioOutput * m_audioOutput;

    QNetworkAccessManager m_nam;

public slots:
    void onTimerTimeout();
};

#endif // WIDGET_H
